<template>
  <div>
    <van-picker title="修改性别" show-toolbar :columns="columns" @confirm="onConfirm" @cancel="$emit('close-popup')"
      :default-index="value" />
  </div>
</template>

<script>
import { editUserInfo } from '@/api/user.js'
export default {
  name: 'Gender',
  data () {
    return {
      columns: ['男', '女']
    }
  },
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  methods: {
    async onConfirm (val, index) {
      // 自定义加载图标
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true,
        duration: 0
      })
      // console.log('确定')
      try {
        await editUserInfo({
          gender: index
        })
        this.$toast.success('修改性别成功')
        this.$emit('close-popup')
        this.$emit('input', index)
      } catch (err) {
        this.$toast.fail('修改失败')
      }
    }

  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  created () { },
  mounted () { }
}
</script>

<style scoped lang='less'>
</style>
